#include<stdio.h>
#include<string.h>
char *s_gets(char *st,int n);
#define maxtitle 40
#define maxauthor 40
#define maxbooks 100
struct book{
    char title[maxtitle];
    char author[maxauthor];
    float value;
};
int main(void)
{
    struct book library[maxbooks];
    int count=0;
    int index;
    
    printf("please enter the book title.\n");
    printf("please press[enter] at a start of a line to stop.\n");
    while(count<maxbooks && s_gets(library[count].title,maxtitle)!=NULL && library[count].title[0]!='\0')
    {
        printf("Now enter the author.\n");
        s_gets(library[count].author,maxauthor);
        printf("Now enter the value.\n");
        scanf("%f",&library[count++].value);
        while(getchar()!='\n')
            continue;
        if(count<maxbooks)
            printf("enter the nexttitle.\n");
    }
    if(count>0)
    {
        printf("Here is the list of your books:\n");
        for(index=0;index<count;index++)
            printf("%s by %s :$%.2f\n",library[index].title,library[index].author,library[index].value);
    }
    else
        printf("No books? Too bad.\n");
    return 0;

}
char *s_gets(char* st,int n)//用来输入字符串的函数，十分常见
{
    char *ret_val;
    char *find;
    ret_val=fgets(st,n,stdin);
    if(ret_val)
    {
        find=strchr(st,'\n');//查找换行符
        if(find)
            *find='\0';
        else   
            while(getchar()!='\n')
                continue;
    }
    return ret_val;
}